/*
 * Created by JFormDesigner on Tue Jul 02 03:13:54 CST 2024
 */

package scct.hys.ui;

import scct.hys.dao.ScreeningDao;
import scct.hys.model.Screening;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author 26984
 */
public class DlgScreeningUpdate extends JDialog {
    int id;
    public DlgScreeningUpdate(Window owner,int id) {
        super(owner);
        initComponents();
        this.id=id;
        initView();
    }

    private void initView() {
        ScreeningDao screeningDao=new ScreeningDao();
        Screening screening=screeningDao.getScreeningById(id);
        txtMovieName.setText(screening.getMovieid());
        txtStarttime.setText(screening.getStartTime());
        txtPrice.setText(screening.getPrice());
        txtType.setText(screening.getType());
    }


    private void btnUpdate(ActionEvent e) {
        // TODO add your code here
        String movieid=txtMovieName.getText();
        String start=txtStarttime.getText();
        String price= txtPrice.getText();
        String type=txtType.getText();
        ScreeningDao screeningDao=new ScreeningDao();
        if (screeningDao.updateScreening(id,movieid,start,price,type)){
            JOptionPane.showMessageDialog(this,"用户名修改成功");
            dispose();
        }
    }
    private void btnCancel(ActionEvent e) {
        // TODO add your code here
        this.dispose();
    }
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - 韩月生
        label1 = new JLabel();
        txtMovieName = new JTextField();
        label2 = new JLabel();
        txtStarttime = new JTextField();
        label3 = new JLabel();
        txtPrice = new JTextField();
        label4 = new JLabel();
        txtType = new JTextField();
        btnUpdate = new JButton();
        btnCancel = new JButton();

        //======== this ========
        setTitle("\u4fee\u6539\u653e\u6620\u4fe1\u606f");
        var contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u7535\u5f71\u540d\u79f0");
        contentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(40, 35), label1.getPreferredSize()));
        contentPane.add(txtMovieName);
        txtMovieName.setBounds(135, 28, 165, txtMovieName.getPreferredSize().height);

        //---- label2 ----
        label2.setText("\u4e0a\u6620\u65f6\u95f4");
        contentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(40, 70), label2.getPreferredSize()));
        contentPane.add(txtStarttime);
        txtStarttime.setBounds(135, 63, 165, txtStarttime.getPreferredSize().height);

        //---- label3 ----
        label3.setText("\u7968\u4ef7");
        contentPane.add(label3);
        label3.setBounds(new Rectangle(new Point(40, 105), label3.getPreferredSize()));
        contentPane.add(txtPrice);
        txtPrice.setBounds(135, 98, 165, txtPrice.getPreferredSize().height);

        //---- label4 ----
        label4.setText("\u7535\u5f71\u7c7b\u578b");
        contentPane.add(label4);
        label4.setBounds(new Rectangle(new Point(40, 140), label4.getPreferredSize()));
        contentPane.add(txtType);
        txtType.setBounds(135, 133, 165, txtType.getPreferredSize().height);

        //---- btnUpdate ----
        btnUpdate.setText("\u786e\u5b9a\u4fee\u6539");
        btnUpdate.addActionListener(e -> btnUpdate(e));
        contentPane.add(btnUpdate);
        btnUpdate.setBounds(new Rectangle(new Point(55, 190), btnUpdate.getPreferredSize()));

        //---- btnCancel ----
        btnCancel.setText("\u53d6\u6d88");
        btnCancel.addActionListener(e -> btnCancel(e));
        contentPane.add(btnCancel);
        btnCancel.setBounds(new Rectangle(new Point(225, 190), btnCancel.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        setSize(400, 300);
        setLocationRelativeTo(null);
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - 韩月生
    private JLabel label1;
    private JTextField txtMovieName;
    private JLabel label2;
    private JTextField txtStarttime;
    private JLabel label3;
    private JTextField txtPrice;
    private JLabel label4;
    private JTextField txtType;
    private JButton btnUpdate;
    private JButton btnCancel;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
